<script setup>
import { onMounted, onUnmounted } from "vue";
import router from "@/router/index";
import { _$, $, to } from "./index";

onMounted(() => {
  $.onSearch();
});

onUnmounted(() => {
  $.clean();
});
</script>

<template>
  <el-space direction="vertical" fill wrap class="w-fill" :size="20">
    <el-page-header @back="router.back()" size="small">
      <template #content>
        <span class="text-large font-600 mr-3">资讯分类管理</span>
      </template>
    </el-page-header>
    <el-card class="w-fill" shadow="never">
      <el-form
        label-width="auto"
        :inline="true"
        :model="_$.query.requestParam"
        size="small"
        class="demo-form-inline"
      >
        <el-form-item label="资讯标题">
          <el-input v-model="_$.query.requestParam.condition" clearable />
        </el-form-item>
        <el-form-item>
          <el-space wrap>
            <el-button @click="$.onReset">重置</el-button>
            <el-button type="primary" @click="$.onSearch">查询</el-button>
          </el-space>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="w-fill" shadow="never">
      <el-space direction="vertical" fill wrap class="w-fill" :size="20">
        <div style="display: flex; align-items: center">
          <el-space wrap :size="10">
            <el-button
              type="primary"
              size="small"
              @click="router.push('/manage/news-type/edit')"
              >新增</el-button
            >
            <el-tooltip content="请先选择需要删除的数据" placement="right">
              <el-button
                type="warning"
                size="small"
                @click="$.onDelete"
                :disabled="_$.delete.requestParam.ids.length === 0"
                >删除</el-button
              >
            </el-tooltip>
          </el-space>
        </div>
        <el-table
          :data="_$.query.responseParam.records"
          size="small"
          stripe
          style="width: 100%; height: 500px"
          @selection-change="$.handleSelectionChange"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column type="index" label="序号" width="60" />
          <el-table-column label="操作" width="60">
            <template #default="scope">
              <el-button
                icon="edit"
                size="small"
                link
                @click="
                  $router.push('/manage/news-type/edit?id=' + scope.row.id)
                "
              />
            </template>
          </el-table-column>
          <el-table-column prop="title" label="分类名称">
            <template #default="scope">
              <el-button
                type="primary"
                link
                @click="to.goToDetail(scope.row.id)"
              >
                {{ scope.row.name }}
              </el-button>
            </template>
          </el-table-column>
          <el-table-column prop="cdate" label="创建时间" align="center" />
          <el-table-column prop="edate" label="更新时间" align="center" />
        </el-table>
        <div style="display: flex">
          <div class="flex-grow" />
          <el-pagination
            v-model:current-page="_$.query.requestParam.pageNum"
            v-model:page-size="_$.query.requestParam.pageSize"
            :page-sizes="[20, 50, 100, 200]"
            :small="true"
            layout="total, sizes, prev, pager, next, jumper"
            :total="_$.query.responseParam.total"
            @size-change="$.handleSizeChange"
            @current-change="$.handleCurrentChange"
          />
        </div>
      </el-space>
    </el-card>
  </el-space>
</template>

<style scoped></style>
